Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors when using rust-analyzer with canister method attributes #237

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

Maximkaaa
Copy link
Collaborator

This commit removes checks by the query, update and init macroses that there are duplicate methods with the same name.

The reason this causes an issue is that in contrast with the rustc, rust-analyzer expands macroses using the same process all the time. This means that lazy_static storage for the macro is not dropped between invocations which produces the error. After this change, the new declaration of the method expanded by the rust-analyzer will just replace the old one.

This will change will also make the macros' implementation more correct for 2 reasons:

  1. The checks we had are not reliable. They only check for duplication inside one crate, which in most cases is already coverred by the compiler when it check that there are no 2 methods with the same name.
  2. Even if there are 2 method with the same name (in the same crate or across the crates), compiler will still report an error because these methods are exported by the WASM module with the same name. Such error method is more difficult to read then the ones we had, but it is more correct and works 100% of the time, which is more important.

This commit removes checks by the `query`, `update` and `init` macroses
that there are duplicate methods with the same name.

The reason this causes an issue is that in contrast with the rustc,
rust-analyzer expands macroses using the same process all the time.
This means that lazy_static storage for the macro is not dropped
between invocations which produces the error. After this change, the
new declaration of the method expanded by the rust-analyzer will just
replace the old one.

This will change will also make the macros' implementation more correct
for 2 reasons:

1. The checks we had are not reliable. They only check for duplication
   inside one crate, which in most cases is already coverred by the
   compiler when it check that there are no 2 methods with the same
   name.
2. Even if there are 2 method with the same name (in the same crate or
   across the crates), compiler will still report an error because these
   methods are exported by the WASM module with the same name. Such
   error method is more difficult to read then the ones we had, but it
   is more correct and works 100% of the time, which is more important.
Copy link
Collaborator

@ufoscout ufoscout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Maximkaaa There are lint errors to be fixed

@ufoscout ufoscout merged commit df53171 into main Dec 2, 2024
1 check passed
@ufoscout ufoscout deleted the maxim/fix_ra_errors branch December 2, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants